// const menu = {
//   uid: 'back-home',
//   name: '返回首页',
//   children: [
//     { children: [], info: { hint: '返回首页', order: '99' }, name: '返回首页' },
//     { children: [], info: {}, name: '注销登录', uid: 'logout' }
//   ],
//   info: {
//     hint: '返回首页',
//     icon: 'frame_cockpit/return.svg',
//     order: '99'
//   }}
import { getGenealogyFormat } from '@service/utilTool.js'
import service from '@service/httpRequest.js'
export default {

  namespaced: true,
  state: {
    module: [],
    menuList: [],
    favourite: [],
    station: {}
  },
  mutations: {
    setModule(state, payload = []) {
      state.module = payload
    },

    setMenuList(state, payload = []) {
      state.menuList = payload
    },
    setFavourite(state, payload = []) {
      state.favourite = payload
    },
    setStation(state, payload = {}) {
      state.station = payload
    }
  },
  getters: {
    menu: state => {
      // return [...getGenealogyFormat(state.menuList), menu]
      return getGenealogyFormat(state.menuList)
    }
  },
  actions: {
    async init({ dispatch }) {
      // await dispatch('getModule')
      await dispatch('getMenu', { data: {}})
      // dispatch('getFavourite')
      // await dispatch('getStation')
    },
    async getStation({ commit, rootState }) {
      // const payload = {}
      // const result = await rootState.service.getStationInfo()
      // if (result.flag && result.data) {
      //   for (const item of result.data) {
      //     if (item) {
      //       payload[item.id] = item
      //     }
      //   }
      //   commit('setStation', payload)
      // }
    },
    async getModule({ commit, rootState }) {
      const result = await rootState.service.getModule()
      if (result.flag && result.data) {
        commit('setModule', result.data)
      }
    },
    async getMenu({ commit, rootState }, { data }) {
      // const result = await rootState.service.getMenu(data)
      const result = await service.fetchByJson(2004, [{ ...data, uid: '05265ef0-7b6d-4fc5-b496-4080b5cefac1' }])
      // console.log(result.data,'7777777')
      if (result.flag && result.data) {
        commit('setMenuList', result.data)
      }
    },
    async getFavourite({ commit, rootState }) {
      const result = await rootState.service.getFavourite()
      if (result.flag && result.data) {
        commit('setFavourite', result.data)
      }
    },
    async addFavourite({ dispatch, rootState }, data) {
      const result = await rootState.service.addFavourite(...data)
      if (result.flag) {
        dispatch('getFavourite')
      }
    },
    async deleteFavourite({ dispatch, rootState }, data) {
      const result = await rootState.service.deleteCi(...data)
      if (result.flag) {
        dispatch('getFavourite')
      }
    }
  }
}
